<!--
* @description 新增帖子
* @fileName bbs_add.vue
* @author huangyu
* @date 2023/04/21 09:25:17
!-->
<template>
    <div>
        <el-form :model="form" label-width="120px" ref="refsForm" :rules="rules">
            <el-form-item label="帖子主题">
                <el-select v-model="form.type">
                    <el-option :label="item.label" :value="item.value" v-for="(item,index) in typeList" :key="index"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="帖子标题" prop="title">
                <el-input v-model="form.title"></el-input>
            </el-form-item>
            <el-form-item label="帖子内容" prop="content">
                <wangEditor  v-model="form.content" :isClear="false" :height="300"></wangEditor>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="clickSubmitAdd('refsForm')">保存</el-button>
            </el-form-item>
        </el-form>
        <!--  -->
    </div>
</template>

<script>
import { get } from '@/common/app.js'
import wangEditor from "@/components/system/wangEditor.vue"
export default {
    components: {wangEditor},
    data() {
        return {
            token: this.$store.state.token,
            form: {
                type: 1,
                title: "",
                content: "",
            },
            typeList: [],
            rules: {
                title: [ { required: true, message: '请输入帖子标题', trigger: 'change' } ],
                content: [ { required: true, message: '请输入帖子内容', trigger: 'change' } ],
            }
        }
    },
    mounted() {
        this.getbbsType()
    },
    methods: {
        getbbsType(){
            let params = {
                type: 'getBbs',
                api: 'api-bbs-enum',
                data: {
                    type:"bbsType"
                },
            }
            get('game', params).then(res => {
                if (res) {
                    this.typeList = res
                    console.log(res)
                }
            })
        },
        clickSubmitAdd(formName){
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.submitAdd()
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },

        submitAdd(){
            let params = {
                type: 'getBbs',
                api: 'api-bbs-add',
                token: this.token,
                data: this.form,
            }
            get('game', params).then(res => {
                if (res) {
                    this.$message.success("新增帖子成功！")
                    this.form.title = ""
                    this.form.content = ""
                    this.$emit('addSuccess')
                }
            })
        }

    },
}
</script>

<style scoped>

</style>